package org.itzheng.yuezhi.real.tools.login;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;

import com.umeng.socialize.UMAuthListener;
import com.umeng.socialize.UMShareAPI;
import com.umeng.socialize.UMShareConfig;
import com.umeng.socialize.bean.SHARE_MEDIA;

import org.itzheng.utils.common.ActivityAnimUtil;
import org.itzheng.yuezhi.R;
import org.itzheng.yuezhi.adapter.CommonMenuInfoRcvAdapter;
import org.itzheng.yuezhi.base.BaseActivity;
import org.itzheng.yuezhi.entity.MenuInfo;
import org.itzheng.yuezhi.utils.comm.UIUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by admin on 2017/7/20.
 */

public class ThirdPartyLoginActivity extends BaseActivity {

    @BindView(R.id.rcvContent)
    RecyclerView rcvContent;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
//        overridePendingTransition(R.anim.push_left_in, R.anim.push_left_out);
        super.onCreate(savedInstanceState);
        setTitle("登录");
        setContentView(R.layout.common_container_recycler_view);
        ButterKnife.bind(this);
        setAdapter();
    }

    CommonMenuInfoRcvAdapter adapter;

    private void setAdapter() {
        if (adapter == null) {
            rcvContent.setLayoutManager(new LinearLayoutManager(UIUtils.getContext()));
            rcvContent.setAdapter(new CommonMenuInfoRcvAdapter(getMenuList()));
        } else {
            adapter.notifyDataSetChanged();
        }
    }

    private List<MenuInfo> getMenuList() {
        List<MenuInfo> menuInfoList = new ArrayList<>();
        MenuInfo qqLogin = new MenuInfo();
        qqLogin.title = "QQ登录";
        qqLogin.onClickListener = new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                qqLogin();
            }
        };
        menuInfoList.add(qqLogin);
        MenuInfo wchatLogin = new MenuInfo();
        wchatLogin.title = "微信登录";
        wchatLogin.onClickListener = new View.OnClickListener() {
            @Override
            public void onClick(View view) {

            }
        };
        menuInfoList.add(wchatLogin);
        return menuInfoList;
    }

    private static final String TAG = "ThirdPartyLoginActivity";

    public void qqLogin() {
        UMShareConfig config = new UMShareConfig();
        config.isNeedAuthOnGetUserInfo(true);
        UMShareAPI.get(this).setShareConfig(config);
        UMShareAPI.get(this).getPlatformInfo(this, SHARE_MEDIA.QQ, new UMAuthListener() {
            @Override
            public void onStart(SHARE_MEDIA share_media) {
                Log.d(TAG, "onStart");
            }

            @Override
            public void onComplete(SHARE_MEDIA share_media, int i, Map<String, String> map) {
                Log.d(TAG, "onComplete" + map.toString());
            }

            @Override
            public void onError(SHARE_MEDIA share_media, int i, Throwable throwable) {
                Log.d(TAG, "onError" + throwable.getMessage());
            }

            @Override
            public void onCancel(SHARE_MEDIA share_media, int i) {
                Log.d(TAG, "onCancel");
            }
        });
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        UMShareAPI.get(this).onActivityResult(requestCode, resultCode, data);
    }

    @Override
    public void finish() {
        super.finish();
        ActivityAnimUtil.finishDefaultAnim(this);
//        overridePendingTransition(R.anim.pull_right_in, R.anim.pull_right_out);
    }
}
